import { ref } from "vue"
import service from "@/axios"

export default function useItem() {
    const items = ref([]);
    const userItemVo = ref([]);
    const itemVos = ref([]);

    async function getAllItems() {
        try {
            const response = await service.get("/items");
            items.value = response.data.data;
        } catch (error) {
            console.error(error);
        }
    }

    async function getUserItems(userId) {
        try {
            const response = await service.get(`/myItem?userId=${userId}`);
            userItemVo.value = response.data.data;
        } catch (error) {
            console.error(error);
        }
    }

    async function getAllItemVos() {
        try {
            const response = await service.get("/itemRecord");
            itemVos.value = response.data.data;
        } catch (error) {
            console.error(error);
        }
    }

    return {
        items,
        userItemVo,
        itemVos,
        getAllItems,
        getUserItems,
        getAllItemVos
    }
}